<template>
  <el-dialog :title="$t('table.detail')" width="560px" :visible.sync="visible" @close="onClose">
    <el-form :model="form" size="small">
      <el-form-item :label="$t('userGroup.name')">
        <el-input :value="form.name" readonly></el-input>
      </el-form-item>
      <el-form-item :label="$t('userGroup.autoAuth')">
        <i class="el-alert--success el-icon-success" v-if="form.autoAuth"></i>
        <i class="el-alert--error el-icon-error" v-else></i>
      </el-form-item>
      <el-form-item :label="$t('userGroup.peerAuth')">
        <i class="el-alert--success el-icon-success" v-if="form.peerAuth"></i>
        <i class="el-alert--error el-icon-error" v-else></i>
      </el-form-item>
      <el-form-item :label="$t('userGroup.childAuth')">
        <i class="el-alert--success el-icon-success" v-if="form.childAuth"></i>
        <i class="el-alert--error el-icon-error" v-else></i>
      </el-form-item>
      <el-form-item :label="$t('userGroup.parent')">
        <el-input :value="form.parent | parentFormatter" readonly></el-input>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
  import { vsprintf } from 'sprintf-js/dist/sprintf.min.js'
  import { commonFilters } from '@/utils/utils'

  export default {
    data() {
      var form = Object.assign({}, this.$parent.selectedRow);
      return {
        visible: true,
        form: form
      };
    },
    methods: {
      onClose(){
        this.$router.push("/");
      }
    },
    filters: {
      parentFormatter(val){
        if(val){
          return val.name;
        }
        return '';
      }
    }
  };
</script>
